// components/Kefu/index.js
import { getServiceInfoApi } from '../../api/common'
Component({
  options: {
    styleIsolation: 'apply-shared'
  },
  /**
   * 组件的属性列表
   */
  properties: {},

  /**
   * 组件的初始数据
   */
  data: {
    serviceInfo: {}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async getServiceInfo() {
      const [err, data] = await getServiceInfoApi()
      if (err) return
      this.setData({
        serviceInfo: data
      })
    },
    showModle() {
      this.setData({
        show: true
      })
    },
    onClose() {
      this.setData({ show: false })
    },
    callHandle() {
      wx.makePhoneCall({
        phoneNumber: this.data.serviceInfo.tel,
        success: () => {},
        fail: () => {
          wx.showToast({
            title: '拨打电话失败',
            icon: 'none'
          })
        }
      })
    }
  },
  lifetimes: {
    attached() {
      this.getServiceInfo()
    }
  }
})
